import axios from 'axios'; // 引入axios
import { Message } from "element-ui"//消息提醒（showToast）
import AOS from 'aos';

const service = axios.create({
  baseURL: '', // url = base api url + request url
  withCredentials: true, // send cookies when cross-domain requests
  timeout: 1000 * 12 // 请求超时
})
// 设置post请求头
service.defaults.headers.post['Content-Type'] = 'application/json; charset=utf-8';
// 请求拦截器
service.interceptors.request.use(
  config => {
    // config.headers['XX-token'] = localStorage.getItem('token');
    config.headers['XX-Device-Type'] = 'web'
    return config
  },
  error => {
    // do something with request error

    return Promise.reject(error)
  }
)
// 响应拦截器
service.interceptors.response.use(
  response => {
    if (response.status == 200) {
      if (response.data.code == 0) {
        Message.closeAll()
        Message({
          message: response.data.msg,
          type: "error",
          showClose: true,
          offset: 100
        })
      }

    }
    setTimeout(() => {
      AOS.refresh();
    }, 100);
    return Promise.resolve(response.data);
  },

  error => {
    console.log(error);

  });
//最后导出实例
export default service;